const express = require('express');
const asyncHandler = require('express-async-handler');
const basicControl = require('../controllers/basic.controller');
const router = express.Router();
module.exports = router;

//根据时间区间获取当前工地环境统计信息

//根据搜索内容获取对应的环境事件
router.post('/getLeanHistoryByDuration', asyncHandler(getLeanHistoryByDuration));
// router.post('/getLeanViolationByDuration', asyncHandler(getLeanViolationByDuration));
router.post('/getLeanReportsByType', asyncHandler(getLeanReportsByType));
router.post('/getThumbnailByType', asyncHandler(getThumbnailByType));

//获取环境模块统计信息
router.post('/getLeanInfoByDuration', asyncHandler(getLeanInfoByDuration));
router.post('/getLeanViolationByDuration', asyncHandler(getLeanViolationByDuration));

router.post('/deleteLeanViolation', asyncHandler(deleteLeanViolation))

async function getLeanInfoByDuration(req, res) {
    let result = await basicControl.getBasicInfoByDuration(req.body, 'lean')
    res.json(result)
}


async function getLeanHistoryByDuration(req, res) {
    let result = await basicControl.getEventsWithTypeByDuration(req.body, 'lean_history')
    res.json(result)
}

// async function getLeanViolationByDuration(req, res) {
//     let result = await basicControl.getEventsWithTypeByDuration(req.body, 'lean_violation')
//     res.json(result)
// }

async function getLeanReportsByType(req, res) {
    let result = await basicControl.getReprtsWithTypeByDuration(req.body)
    res.json(result)
}

async function getThumbnailByType(req, res) {
    let result = await basicControl.getThumbnailByType(req.body)
    console.log(result)
    res.json(result)
}

async function getLeanViolationByDuration(req, res) {
    let result = await basicControl.getLeanViolationByDuration(req.body);
    res.json(result)
}

async function deleteLeanViolation(req, res) {
    let result = await basicControl.deleteViolationData(req.body, 'lean')
    res.json(result)
}